import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main{

    public int LastRemaining_Solution (int n, int m) {

        m = m % n - 1;

        ArrayList<Integer> arr = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            arr.add(i);
        }
        int i = 1;
        while (arr.size() != 1) {
            arr.remove(arr.get(m));
            m = Math.abs(m % arr.size() - 1 - i++) % n;
        }
        return arr.get(0);
    }



    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main1(String[] args)throws IOException {
        Read in = new Read();
        int a = in.nextInt();
        out.println(a);
        out.close();
    }

    public static void main2(String[] args) {
        ArrayList<ArrayList<Integer>> grid = new ArrayList<>();
        ArrayList<Integer> a1 = new ArrayList<>();
        ArrayList<Integer> b = new ArrayList<>();
        ArrayList<Integer> c = new ArrayList<>();

        a1.add(2);
        a1.add(1);
        a1.add(1);
        grid.add(a1);
        b.add(1);
        b.add(0);
        b.add(1);
        grid.add(b);
        c.add(1);
        c.add(1);
        c.add(1);
        grid.add(c);

        System.out.println(rotApple(grid));
    }
    static int[] dx = {-1,1,0,0};
    static int[] dy = {0,0,-1,1};
    static int n,m;
    public static int rotApple (ArrayList<ArrayList<Integer>> grid) {
        n = grid.size();
        m = grid.get(0).size();


        for(int i = 0;i < n;i++){
            for(int j = 0;j < m;j++){
                if(grid.get(i).get(j) == 2){
                    dps(grid,i,j);
                }
            }
        }
        if(count == 0) return(-1);
        else return count;
    }
     static int count = 0;
    static void dps(ArrayList<ArrayList<Integer>> grid,int i,int j){

        int x,y;
        boolean flat = false;
        for(int k = 0;k < 4;k++){
            x = dx[k] + i;y = dy[k] + j;
            if(x >= 0 && x < n && y >= 0 && y < m && grid.get(x).get(y) != 0 && grid.get(x).get(y) != 2 ){
                grid.get(x).set(y,2);
                flat = true;
            }
        }
        if(flat) count++;
    }
}

class Read{
    StringTokenizer st = new StringTokenizer("");
    BufferedReader read = new BufferedReader(new InputStreamReader(System.in));

    String next() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(read.readLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException{
        return read.readLine();
    }

    int nextInt() throws IOException{

        return Integer.parseInt(next());
    }
    long nextLong() throws IOException{

        return Long.parseLong(next());
    }
    double nextDouble() throws IOException{

        return Double.parseDouble(next());
    }
}

class Solution1 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param n int整型
     * @param m int整型
     * @return int整型
     */
    public int LastRemaining_Solution (int n, int m) {

        int index = (m  -1) % n;

        ArrayList<Integer> arr = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            arr.add(i);
        }

        while (arr.size() != 1) {
            arr.remove(arr.get(index));

            index = (index + m - 1) % arr.size();

        }
        return arr.get(0);

    }

    public static void main2(String[] args) {
        Solution1 solution = new Solution1();
        System.out.println(solution.LastRemaining_Solution(10,17));


    }

    public String solve (String s, String t) throws NumberFormatException {

        if(s.equals("") && t.equals("")) return s;
        if(s.equals("") && !t.equals("")) return t;
        if(!s.equals("") && t.equals("")) return s;

        long a = Long.parseLong(s);
        long b = Long.parseLong(t);

        long c = a + b;

        return Long.toString(c);
    }

}

class Solution2 {

    public static void main(String[] args) {
        Solution2  s1  = new Solution2();
        Solution2  s2  = new Solution2();

        ListNode n1 = new ListNode(9);
        ListNode n2 = new ListNode(3);
        n1.next = n2;
        ListNode n3 = new ListNode(7);
        n2.next = n3;

        ListNode n4 = new ListNode(6);
        ListNode n5 = new ListNode(3);
        n4.next = n5;
        ListNode head = addInList(n1,n4);
    }


      static public class ListNode {
       int val;
       ListNode next = null;
       public ListNode(int val) {
         this.val = val;
      }
    }
    public static ListNode addInList (ListNode head1, ListNode head2) {
         int size1 =0,size2 =0;
         ListNode t1 = head1,t2 = head2;
        while(t1 != null){
            size1++;
            t1 = t1.next;
        }
        while(t2 != null){
            size2++;
            t2 = t2.next;
        }
        int sum1 = 0,sum2 =0;

        ListNode tem1 = head1;
        while(tem1 != null){
            sum1 += tem1.val * Math.pow(10,--size1);
            tem1 = tem1.next;
        }
        ListNode tem2 = head2;
        while(tem2 != null){
            sum2 += tem2.val * Math.pow(10,--size2);
            tem2 = tem2.next;
        }
        int sum = sum1 + sum2;

        ListNode head = null;

        char[] ch = Integer.toString(sum).toCharArray();
        for(int i = 0;i < ch.length;i++) {

            ListNode newNode = new ListNode(ch[i] - '0');

            if (head == null) {
                head = newNode;
            } else {
                ListNode cur = search(head);
                cur.next = newNode;
            }
        }


        return head;
    }
    private static ListNode search(ListNode head){

        while(head.next != null){
            head = head.next;
        }

        return head;
    }
}